from django.shortcuts import render, redirect
from formtest import models


# Create your views here.

# 登录页
def login(request):
    return render(request, 'formtest/login.html')

# 登录验证进入表单
def index(request):
    q = request.GET.get('check')
    if not q:
        return render(request, 'formtest/login.html')
    else:
        try:
            user = models.SubmitPassword.objects.get(password=q)
            return render(request, 'formtest/questionnaire.html')
        except:
            return render(request, 'formtest/login.html')


# 提交到数据库
def submit(request):
    # 1.门诊编号
    od_number = request.GET.get('odnumber')
    print("门诊编号"+od_number)
    # 2.姓名
    name = request.GET.get('name')
    print("姓名" + name)
    # 3.性别 male为男性，female为女性
    sex = request.GET.get('Sex')
    print('性别', sex)
    # 4.出生年月
    birthYear = request.GET.get('birthYear')
    birthMonth = request.GET.get('birthMonth')
    birthDay = request.GET.get('birthDay')
    birth = birthYear + "_" + birthMonth + "_" + birthDay
    print("出生日期"+birth)
    # 5.学历
    education = request.GET.get('education')
    print("学历", education)
    # # 6.手机号,
    phone = request.GET.get('phoneNumber')
    print("手机号", phone)
    # # 7.微信号
    chatNumber = request.GET.get('chatNumber')
    print("微信号", chatNumber)
    # # 8.现居地址
    # 省
    address1 = request.GET.get('address1')
    # 市
    address2 = request.GET.get('address2')
    # 区
    address3 = request.GET.get('address3')
    print("居住地", address1, address2, address3)
    # 详细住址
    address = request.GET.get('address')
    print("详细住址", address)
    # # 9.初次性行为年龄
    age = request.GET.get('firstSexAge')
    print("初次性行为年龄", age)
    # # 10.性行为对象
    sextrue = request.GET.get('sexObject')
    print("性行为对象", sextrue)
    # # 11.性行为人数
    nature_number = request.GET.get('sexNum')
    print("性行为人数", nature_number)
    # # 12.近六个月性伴侣人数
    sixNatureNumber = request.GET.get('sixSexNum')
    print("近六个月性伴侣人数", sixNatureNumber)
    # # 13.是否有多人性行为 有为true没有为false
    many_nature = request.GET.get('multiSex')
    print("多人性行为", many_nature)
    # # 14.平均性生活时间
    nature_time = request.GET.get('sexTime')
    print("平均性生活时间", nature_time)
    # # 15.男-男性方式
    twoMan_nature = request.GET.get('m2m')
    print("男男性方式", twoMan_nature)
    # # 16.男-女性方式
    manWoman_nature = request.GET.get('m2f')
    print("男女性方式", manWoman_nature)
    # # 17.女-女性方式
    twoWoman_nature = request.GET.get('f2f')
    print("女女性方式", twoWoman_nature)
    # # 18.女-男性方式
    womanWman_nature = request.GET.get('f2m')
    # print("女女性方式", womanWman_nature)
    # 19.几人同时
    mannumber = request.GET.get('sameTimeSex')
    print('几人同时', mannumber)
    # 20.男女比例
    manwuman = request.GET.get('manwuman')
    print('男女比例', manwuman)
    # 向数据库添加
    models.FormInfo.objects.create(
        od_number=od_number,
        name=name,
        sex=sex,
        birthday=birth,
        education=education,
        phone=phone,
        chatNumber=chatNumber,
        address=address,
        age=age,
        nature_object=sextrue,
        nature_number=nature_number,
        sixNatureNumber=sixNatureNumber,
        many_nature=many_nature,
        nature_time=nature_time,
        # 男男
        twoMan_nature=twoMan_nature,
        # 男女
        manWoman_nature=manWoman_nature,
        #女女
        twoWoman_nature=twoWoman_nature,
        #女男
        womanWman_nature=womanWman_nature,

        sexnumber=mannumber,
        mannumber=manwuman,
    )
    return render(request, 'formtest/questionnaire.html')

